#ifndef MARKET_DATA_MANAGER_HPP
#define MARKET_DATA_MANAGER_HPP

#include "stock.hpp"
#include <QObject>
#include <QTimer>
#include <QVector>
#include <nlohmann/json.hpp>

class MarketDataManager : public QObject {
  Q_OBJECT

public:
  explicit MarketDataManager(QObject *parent = nullptr);
  ~MarketDataManager();

  // 初始化股票数据
  bool loadStocks(const QString &filePath = "data/stocks.json");

  // 保存股票数据
  bool saveStocks(const QString &filePath = "data/stocks.json");

  // 启动市场模拟
  void startSimulation(int interval = 500); // 默认2秒更新一次

  // 停止市场模拟
  void stopSimulation();

  // 获取股票列表
  QVector<Stock> &getStocks();
  const QVector<Stock> &getStocks() const;

  // 根据代码查找股票
  Stock *findStock(const QString &code);

signals:
  // 市场数据更新信号
  void marketUpdated();

private:
  QVector<Stock> m_stocks;
  QTimer *m_timer;
  bool m_isSimulating;
};

#endif // MARKET_DATA_MANAGER_HPP
